package com.akkainaction.remote.event;

import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
import akka.actor.UntypedActor;
import com.typesafe.config.ConfigFactory;

import java.sql.Time;
import java.util.concurrent.TimeUnit;

/**
 * Api版本：RemoteServer
 */
public class RemoteServerActor extends UntypedActor {

    @Override
    public void onReceive(Object message) throws Exception {
        if(message instanceof String){
            System.out.println("remote server 收到消息:"+message);
            getSender().tell("remote server 发送回执消息!",getSelf());
        }
    }

    public static void main(String[] args) {
        ActorSystem system = ActorSystem.create("sys", ConfigFactory.load("remote-server.conf"));
        system.actorOf(Props.create(MonitorActor.class),"monitor");
        ActorRef actorRef = system.actorOf(Props.create(RemoteServerActor.class), "remoteServer");
        try {
            TimeUnit.SECONDS.sleep(30);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        system.shutdown();
        try {
            TimeUnit.MINUTES.sleep(5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
